//
//  MaterialTableViewCell.m
//  Cooking
//
//  Created by ZhiPeng.Y on 15/9/2.
//  Copyright (c) 2015年 ZP.Y. All rights reserved.
//

#import "MaterialTableViewCell.h"
#import "AppMacro.h"
#import "MaterialModel.h"
#import "UIImageView+WebCache.h"

@interface MaterialTableViewCell ()

@property (retain, nonatomic) UIImageView *backGroundImage;
@property (retain, nonatomic) UILabel     *materialLabel;
@property (retain, nonatomic) UILabel     *flavourLabel;
@property (retain, nonatomic) UIImageView *foodImage ;

@end

@implementation MaterialTableViewCell

- (void)dealloc {
    [_backGroundImage release];
    [_materialImage release];
    [_materialLabel release];
    [_flavourLabel release];
    [_foodImage release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createView];
    }
    return self;
}

- (void)createView {
    
    self.materialLabel = [[UILabel alloc] init];
//    _materialLabel.backgroundColor = [UIColor grayColor];
    _materialLabel.numberOfLines = 3;
    _materialLabel.font = [UIFont systemFontOfSize:15];
    _materialLabel.textColor = [UIColor brownColor];
    [self.contentView addSubview:_materialLabel];
    [_materialLabel release];
    
    self.backGroundImage = [[UIImageView alloc] init];
    //    _backGroundImage.backgroundColor = [UIColor greenColor];
    _backGroundImage.image = [self imageWithName:@"backGround" type:@"png"];
    [self.contentView addSubview:_backGroundImage];
    [_backGroundImage release];
    
    self.materialImage = [[UIImageView alloc] init];
//    _materialImage.backgroundColor = [UIColor purpleColor];
    [_backGroundImage addSubview:_materialImage];
    [_materialImage release];
    
    self.flavourLabel= [[UILabel alloc] init];
//    _flavourLabel.backgroundColor = [UIColor grayColor];
    _flavourLabel.numberOfLines = 3;
    _flavourLabel.font = [UIFont systemFontOfSize:15];
    _flavourLabel.textColor = [UIColor brownColor];
    [self.contentView addSubview:_flavourLabel];
    [_flavourLabel release];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    _materialLabel.frame = CGRectMake(30, 10, WIDTH - 60, 80);
    _backGroundImage.frame = CGRectMake(60, _materialLabel.frame.origin.y + _materialLabel.frame.size.height + 1, WIDTH - 120, HEIGHT / 3 - 50);
    _flavourLabel.frame = CGRectMake(30, _backGroundImage.frame.origin.y + _backGroundImage.frame.size.height + 1, WIDTH - 60, 60);
    _materialImage.frame = CGRectMake(10, 10, _backGroundImage.frame.size.width - 20, _backGroundImage.frame.size.height - 22.5);
}

- (UIImage *)imageWithName:(NSString *)imageName type:(NSString *)imageType {
    NSString *path = [[NSBundle mainBundle] pathForResource:imageName ofType:imageType];
    UIImage *image = [UIImage imageWithContentsOfFile:path];
    return image;
}

- (void)sendValueWithModel:(MaterialModel *)stepModel {
    NSString *materialStr = [NSString stringWithFormat:@"原料:%@", stepModel.fittingRestriction];
    _materialLabel.text = materialStr;
    if ([stepModel.method isEqualToString:@""]) {
        NSString *flavourStr = @"调料:无";
        _flavourLabel.text = flavourStr;
    } else {
    NSString *flavourStr = [NSString stringWithFormat:@"调料:%@", stepModel.method];
    _flavourLabel.text = flavourStr;
    }
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
